package com.fr.web;

import com.fr.base.FRContext;
import com.fr.base.core.BaseCoreUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.FRCoreContext;
import com.fr.base.core.RSADecode;
import com.fr.base.core.json.JSONObject;
import com.fr.base.file.ConfigManager;
import com.fr.privilege.filter.core.FRSecurityDispatcher;
import com.fr.util.Consts;
import com.fr.web.core.ErrorHandlerHelper;
import com.fr.web.core.ReportDispatcher;
import com.fr.web.core.ServerEnv;
import com.fr.web.core.gzip.GZIPResponseWrapper;
import com.fr.web.platform.exception.RedirectException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Calendar;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ReportServlet extends HttpServlet
{
  private static final long serialVersionUID = 2204797189775876731L;

  public void init(ServletConfig paramServletConfig)
    throws ServletException
  {
    super.init(paramServletConfig);
    FRContext.setLanguage(FRContext.getConfigManager().getServerLanguage());
    ServletContext localServletContext = getServletContext();
    try
    {
      if (FRContext.getCurrentEnv() == null)
        FRContext.setCurrentEnv(new ServerEnv(localServletContext));
    }
    catch (Exception localException1)
    {
      FRContext.getLogger().log(Level.WARNING, localException1.getMessage());
    }
    localServletContext.setAttribute(getClass().getName(), this);
    int i = 0;
    byte[] arrayOfByte = FRCoreContext.getBytes();
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    try
    {
      RSADecode.decode(arrayOfByte, localByteArrayOutputStream);
    }
    catch (Exception localException2)
    {
    }
    try
    {
      JSONObject localJSONObject = new JSONObject(new String(localByteArrayOutputStream.toByteArray(), "UTF-8"));
      String str = paramServletConfig.getServletContext().getRealPath("").substring(paramServletConfig.getServletContext().getRealPath("").lastIndexOf("\\") + 1);
      if ((localJSONObject.getLong("deadline") > Calendar.getInstance().getTimeInMillis()) && (localJSONObject.has("version")) && (ComparatorUtils.equals(Consts.VERSION, localJSONObject.getString("version"))) && (((localJSONObject.getLong("deadline") - Calendar.getInstance().getTimeInMillis() < new Long("3153600000").longValue()) || (!(localJSONObject.has("macaddress"))) || (!(BaseCoreUtils.getMacAddresses().contains(localJSONObject.getString("macaddress")))) || (!(localJSONObject.has("appname"))) || (ComparatorUtils.equals(str, localJSONObject.getString("appname"))))))
        i = 1;
    }
    catch (Exception localException3)
    {
    }
    localServletContext.setAttribute("__initTime_", new Long(System.currentTimeMillis()));
  }

  public void doGet(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws IOException, ServletException
  {
    GZIPResponseWrapper localGZIPResponseWrapper = null;
    try
    {
      String str = paramHttpServletRequest.getHeader("accept-encoding");
      if ((FRContext.getConfigManager().isSupportGzip()) && (!("false".equals(paramHttpServletRequest.getParameter("gzip")))) && (str != null) && (str.indexOf("gzip") != -1) && (Browser.resolve(paramHttpServletRequest).supportGzip()))
        localGZIPResponseWrapper = new GZIPResponseWrapper(paramHttpServletResponse);
      if (localGZIPResponseWrapper != null)
        paramHttpServletResponse = localGZIPResponseWrapper;
      paramHttpServletResponse.addHeader("P3P", "CP=CAO PSA OUR");
      FRSecurityDispatcher.dealWithRequest(paramHttpServletRequest, paramHttpServletResponse);
      ReportDispatcher.dealWithRequest(paramHttpServletRequest, paramHttpServletResponse);
    }
    catch (RedirectException localRedirectException)
    {
      FRContext.getLogger().log(Level.INFO, localRedirectException.getMessage());
    }
    catch (Exception localException)
    {
      FRContext.getLogger().log(Level.SEVERE, localException.getMessage(), localException);
      ErrorHandlerHelper.getErrorHandler().error(paramHttpServletRequest, paramHttpServletResponse, localException);
    }
    finally
    {
      if (localGZIPResponseWrapper != null)
        localGZIPResponseWrapper.finishResponse();
    }
  }

  public void doPost(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws ServletException, IOException
  {
    doGet(paramHttpServletRequest, paramHttpServletResponse);
  }

  public void destroy()
  {
  }
}